#pragma once
#include "../memory/basic_allocator.hpp"

namespace wxx {
namespace com
{
	template<class T>
	struct cotask_allocator : wxx::basic_allocator<T>
	{
		WXX_memory_allocator_rebind(cotask_allocator);

		pointer allocate(size_type count) const
		{
			pointer ptr = reinterpret_cast<pointer>(
				::CoTaskMemAlloc(sizeof(T) * count)
			);

			if (!ptr)
			{
				throw std::bad_alloc();
			}

			return ptr;
		}

		void deallocate(pointer ptr) const
		{
			if (ptr)
			{
				::CoTaskMemFree(ptr);
			}
		}

		void deallocate(pointer ptr, size_type) const
		{
			return deallocate(ptr);
		}

	};
}}